﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Stamp_For_Africa_Version_2.Models;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Controllers
{
	public class TypeController : Controller
	{
		private readonly TypeRepository _typeRepository = new TypeRepository();
		//
		// GET: /Type/

		public ActionResult Index()
		{
			List<StampType> stampTypes = _typeRepository.FindAllTypes().ToList();
			return View(stampTypes);
		}

		public ActionResult Create()
		{
			return View();
		}

		public ActionResult Details(Guid id)
		{
			StampType type = _typeRepository.GetStampType(id);
			return View(type);
		}
		public ActionResult Edit(Guid id)
		{
			StampType type = _typeRepository.GetStampType(id);
			return View(type);
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Edit(Guid id, FormCollection formValues)
		{
			StampType type = _typeRepository.GetStampType(id);
			if (type != null)
			{
				try
				{
					UpdateModel(type);
				}
				catch (Exception)
				{
					return RedirectToAction("Edit", new {id});
					
				}
			}
			return RedirectToAction("Details", new {id});
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Create(StampType type)
		{
			type.Id = Guid.NewGuid();
			_typeRepository.AddStampType(type);
			return RedirectToAction("Details", new {id = type.Id});
		}

		
	}
}
